﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Obsidian.GameObjects;
using Microsoft.Xna.Framework.Graphics;
using System.Globalization;

namespace Obsidian.Components
{
    public class Renderer : Component
    {
        public void Draw(DrawingContext context, ref Matrix parentTransform)
        {
            // local variables
            Matrix local, global;
            
            // get this objects transform
            Transform.GetLocalMatrix(out local);
            Matrix.Multiply(ref local, ref parentTransform, out global);
            // render this object
            DrawCore(context, ref global);
            // render all children with renderers
            foreach (var child in this.GameObject.Children)
            {
                if (child.Renderer != null)
                    child.Renderer.Draw(context, ref global);
            }
        }

        protected virtual void DrawCore(DrawingContext context, ref Matrix global)
        {
            //context.DrawText(context.DebugFont, Transform.LocalPosition.ToString(), Vector2.Zero, Color.Black, ref global);
            //context.DrawText(context.DebugFont, Transform.Position.ToString(), new Vector2(0, 12), Color.Black, ref global);
            //context.DrawText(context.DebugFont, String.Format("{0:F1} L", MathHelper.ToDegrees(Transform.LocalRotation)), new Vector2(0, 0), Color.Black, ref global);
            //context.DrawText(context.DebugFont, String.Format("{0:F1} G", MathHelper.ToDegrees(Transform.Rotation)), new Vector2(0, 12), Color.Black, ref global);
        }

        public Renderer()
            : base("Renderer")
        {

        }

        public Renderer(string name)
            : base(name)
        {

        }
    }
}
